package cn.seecoder.ai.controller;

import cn.seecoder.ai.model.vo.ModelVO;
import cn.seecoder.ai.model.vo.PredictionVO;
import cn.seecoder.ai.model.vo.ResultVO;
import cn.seecoder.ai.service.PredictionService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author fanyanpeng
 * @date 2023/4/16 23:11
 */
@Slf4j
@RestController
@RequestMapping("${apiPrefix}/ml/predictions")
public class PredictionController {


    @Autowired
    PredictionService predictionService;

    @ApiOperation("预测文件")
    @PostMapping("/predict")
    public ResultVO<PredictionVO> predict(@RequestParam Integer userId,
                                        @RequestParam Integer modelId,
                                        @RequestParam Integer fileInfoId){
        return ResultVO.buildSuccess(predictionService.predictAsync(userId,modelId,fileInfoId));
    }

    @ApiOperation("查看当前用户预测结果")
    @GetMapping("")
    public ResultVO<List<PredictionVO>> getPredictionVOList(@RequestParam Integer userId){
        return ResultVO.buildSuccess(predictionService.getPredictionVOList(userId));
    }


    @ApiOperation("查看某一次预测结果")
    @GetMapping("/{predictionId}")
    public ResultVO<PredictionVO> getPredictionVO(@RequestParam Integer userId,
                                                  @PathVariable Integer predictionId){
        return ResultVO.buildSuccess(predictionService.getPredictionVO(userId, predictionId));
    }


    @ApiOperation("查看某个模型下所有预测结果")
    @GetMapping("/models/{modelId}")
    public ResultVO<List<PredictionVO>> getPredictionVOListByModelId(@RequestParam Integer userId,
                                                                     @PathVariable Integer modelId){

        return ResultVO.buildSuccess(predictionService.getPredictionVOList(userId, modelId));

    }


}
